$(function () {
    $("#jqGrid").jqGrid({
        url: '../accidentsmanagement/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true,hidden:true },
			{ label: '员工姓名', name: 'name', index: 'name', width: 80 }, 			
			{ label: '身份证号', name: 'idno', index: 'idno', width: 80,hidden:true },
			{ label: '公司名称', name: 'company', index: 'company', width: 80 }, 			
			{ label: '公司id', name: 'companyId', index: 'company_id', width: 80,hidden:true },
			{ label: '部门', name: 'dept', index: 'dept', width: 80 }, 			
			{ label: '岗位名称', name: 'post', index: 'post', width: 80 }, 			
			{ label: '岗位id', name: 'postId', index: 'post_id', width: 80,hidden:true },
			{ label: '年龄', name: 'age', index: 'age', width: 80 }, 			
			{ label: '性别', name: 'sex', index: 'sex', width: 80 ,formatter:function (value) {
			    if(value=='0'){
			        return "男";
                }else  if(value=='1'){
                    return "女";
                }else {
                    return "";
                }

            }},
			{ label: '联系电话', name: 'phone', index: 'phone', width: 80 }, 			
			{ label: '事故时间', name: 'eventDate', index: 'event_date',  width: 90, formatter:"date", formatoptions: {newformat:'Y-m-d'}
            },
			{ label: '事故地点', name: 'enentPlace', index: 'enent_place', width: 80 }, 			
			{ label: '事故类别', name: 'enentType', index: 'enent_type', width: 80 ,formatter:getDictInfo },
			{ label: '伤亡类别', name: 'casualtyType', index: 'casualty_type', width: 80  ,formatter:getDictInfo},
			{ label: '伤害部位', name: 'injurySite', index: 'injury_site', width: 80 }, 			
			{ label: '伤害程度', name: 'injuryDegree', index: 'injury_degree', width: 80  ,formatter:getDictInfo},
			{ label: '就诊医院', name: 'jzHospital', index: 'jz_hospital', width: 80 }, 			
			{ label: '就诊日期', name: 'jzDate', index: 'jz_date',  width: 90, formatter:"date", formatoptions: {newformat:'Y-m-d'}
            },
			{ label: '就诊方式', name: 'jzfs', index: 'jzfs', width: 80  ,formatter:getDictInfo},
			{ label: '事故概况', name: 'accidentSurvey', index: 'accident_survey', width: 80 }, 			
			{ label: '快报提交日期', name: 'expressSubmissionDate', index: 'express_submission_date', width: 120, formatter:"date", formatoptions: {newformat:'Y-m-d'}
            },
			{ label: '是否认定', name: 'isconfirm', index: 'isConfirm', width: 80 ,
                formatter:function(v){
                    if(v=="0"){
                        return "是";
                    }else if(v=="1"){
                        return "否";
                    }else{
                        return ""
                    }
                } },
			{ label: '认定申请日期', name: 'rdsqrq', index: 'rdsqrq',  width: 110, formatter:"date", formatoptions: {newformat:'Y-m-d'}
            },
				{ label: '鉴定申请日期', name: 'jdsqrq', index: 'jdsqrq',  width: 110, formatter:"date", formatoptions: {newformat:'Y-m-d'}
            },

            { label: '伤残补助', name: 'scbz', index: 'scbz', width: 80 },
            { label: '医疗补助', name: 'ylbz', index: 'ylbz', width: 80 },
            { label: '工亡待遇', name: 'gwdy', index: 'gwdy', width: 80 },
            { label: '认定下达日期', name: 'rdxdrq', index: 'rdxdrq',  width: 110, formatter:"date", formatoptions: {newformat:'Y-m-d'}
            },
            { label: '认定编号', name: 'rdno', index: 'rdno', width: 80 },

            { label: '鉴定编号', name: 'jdno', index: 'jdno', width: 80 },
            { label: '鉴定等级', name: 'jddj', index: 'jddj', width: 80  ,formatter:getDictInfo},
            { label: '发票类型', name: 'invoiceType', index: 'invoice_type', width: 80  ,formatter:getDictInfo},
            { label: '发票金额', name: 'invoiceMoney', index: 'invoice_money', width: 80 },
            { label: '发票数量', name: 'invoiceQuantity', index: 'invoice_quantity', width: 80 },
            { label: '报销提交日期', name: 'reimbursementSubmitDate', index: 'reimbursement_submit_date',width: 110, formatter:"date", formatoptions: {newformat:'Y-m-d'} },
            { label: '报销金额', name: 'reimbursementMoney', index: 'reimbursement_money', width: 100 },
            { label: '伙食补助', name: 'hsbz', index: 'hsbz', width: 100 },
            { label: '回款日期', name: 'hkrq', index: 'hkrq', width: 90, formatter:"date", formatoptions: {newformat:'Y-m-d'}  },
            { label: '回款批次', name: 'hkpc', index: 'hkpc', width: 80 },

            { label: '是否完结', name: 'sfwj', index: 'sfwj', width: 80 ,
                formatter:function(v){
                    if(v=="0"){
                        return "是";
                    }else if(v=="1"){
                        return "否";
                    }else{
                        return ""
                    }
                } },
			{ label: '制表人', name: 'cusername', index: 'cusername', width: 80 },
			{ label: '录入日期', name: 'cdate', index: 'cdate',  width: 110, formatter:"date", formatoptions: {newformat:'Y-m-d'}
            }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        shrinkToFit:false,
        autoScroll: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    vm.getDictList();
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q: {
            dept: null,
            name: null,
            eventDate1: '',
            eventDate2: '',
            dateRange:null,
        },
		showList: true,
        showtable:false,
        showtable1:false,
        showtable2:false,
        showtable3:false,
        showtable4:false,
        showtable5:false,
        showtable6:false,
        showtable7:false,
        showtable8:false,
        showtable9:false,
        showtable10:false,
        dictList1:{},
        dictList2:{},
        dictList3:{},
        dictList4:{},
        dictList5:{},
        dictList6:{},
        dictList7:{},
		title: null,
		accidentsManagement: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
            vm.showtable = false;

            vm.title = "新增";
			vm.accidentsManagement = {
                name:"",
                zgzt:"0"
            };
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.showtable = false;

            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
           // vm.accidentsManagement.jzDate=$("#jzDate").val();
         /*   vm.accidentsManagement.eventDate=$("#eventDate").val();

            vm.accidentsManagement.expressSubmissionDate=$("#expressSubmissionDate").val();
            vm.accidentsManagement.rdsqrq=$("#rdsqrq").val();
            vm.accidentsManagement.jdsqrq=$("#jdsqrq").val();
            vm.accidentsManagement.rdxdrq=$("#rdxdrq").val();
            vm.accidentsManagement.reimbursementSubmitDate=$("#reimbursementSubmitDate").val();
            vm.accidentsManagement.hkrq=$("#hkrq").val();*/
            var url = vm.accidentsManagement.id == null ? "../accidentsmanagement/save" : "../accidentsmanagement/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.accidentsManagement),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../accidentsmanagement/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../accidentsmanagement/info/"+id, function(r){
                vm.accidentsManagement = r.accidentsManagement;
            });
		},
		reload: function (event) {
			vm.showList = true;
            vm.showtable = false;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{
                    'name': vm.q.name, 'company': vm.q.company, 'post': vm.q.post,
                    'dept': vm.q.dept,'enentType': vm.q.enentType,'injuryDegree': vm.q.injuryDegree,'eventDate1': vm.q.eventDate1,'eventDate2': vm.q.eventDate2,
                    'casualtyType': vm.q.casualtyType,'jzfs': vm.q.jzfs,'jddj': vm.q.jddj,'sfwj': vm.q.sfwj,
                },
                page:page
            }).trigger("reloadGrid");
		},
        gskb: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=true;
            vm.showtable2=false;
            vm.showtable3=false;
            vm.showtable4=false;
            vm.showtable5=false;
            vm.showtable6=false;
            vm.showtable7=false;
            vm.showtable8=false;
            vm.showtable9=false;
            vm.showtable10=false;

            vm.title = "工伤快报";
            vm.getInfo(id);
        },
        gsrd: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=false;
            vm.showtable2=true;
            vm.showtable3=false;
            vm.showtable4=false;
            vm.showtable5=false;
            vm.showtable6=false;
            vm.showtable7=false;
            vm.showtable8=false;
            vm.showtable9=false;
            vm.showtable10=false;

            vm.title = "工伤认定";
            vm.getInfo(id);
        },
        ldnljd: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=false;
            vm.showtable2=false;
            vm.showtable3=true;
            vm.showtable4=false;
            vm.showtable5=false;
            vm.showtable6=false;
            vm.showtable7=false;
            vm.showtable8=false;
            vm.showtable9=false;
            vm.showtable10=false;

            vm.title = "劳动能力鉴定";
            vm.getInfo(id);

        },
        scbz: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=false;
            vm.showtable2=false;
            vm.showtable3=false;
            vm.showtable4=true;
            vm.showtable5=false;
            vm.showtable6=false;
            vm.showtable7=false;
            vm.showtable8=false;
            vm.showtable9=false;
            vm.showtable10=false;

            vm.title = "伤残补助";
            vm.getInfo(id);

        },
        ylbz: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=false;
            vm.showtable2=false;
            vm.showtable3=false;
            vm.showtable4=false;
            vm.showtable5=true;
            vm.showtable6=false;
            vm.showtable7=false;
            vm.showtable8=false;
            vm.showtable9=false;
            vm.showtable10=false;

            vm.title = "医疗补助";
            vm.getInfo(id);

        },
        gwdy: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=false;
            vm.showtable2=false;
            vm.showtable3=false;
            vm.showtable4=false;
            vm.showtable5=false;
            vm.showtable6=true;
            vm.showtable7=false;
            vm.showtable8=false;
            vm.showtable9=false;
            vm.showtable10=false;

            vm.title = "工亡待遇";
            vm.getInfo(id);

        },
        rdjg: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=false;
            vm.showtable2=false;
            vm.showtable3=false;
            vm.showtable4=false;
            vm.showtable5=false;
            vm.showtable6=false;
            vm.showtable7=true;
            vm.showtable8=false;
            vm.showtable9=false;
            vm.showtable10=false;


            vm.title = "认定结果";
            vm.getInfo(id);

        },
        jdjg: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=false;
            vm.showtable2=false;
            vm.showtable3=false;
            vm.showtable4=false;
            vm.showtable5=false;
            vm.showtable6=false;
            vm.showtable7=false;
            vm.showtable8=true;
            vm.showtable9=false;
            vm.showtable10=false;

            vm.title = "鉴定结果";
            vm.getInfo(id);

        },
        fybx: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=false;
            vm.showtable2=false;
            vm.showtable3=false;
            vm.showtable4=false;
            vm.showtable5=false;
            vm.showtable6=false;
            vm.showtable7=false;
            vm.showtable8=false;
            vm.showtable9=true;
            vm.showtable10=false;
            vm.title = "费用报销";
            vm.getInfo(id);

        },
        updateHk: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.showtable1=false;
            vm.showtable2=false;
            vm.showtable3=false;
            vm.showtable4=false;
            vm.showtable5=false;
            vm.showtable6=false;
            vm.showtable7=false;
            vm.showtable8=false;
            vm.showtable9=false;
            vm.showtable10=true;
            vm.title = "修改回款";
            vm.getInfo(id);
        },
        popPage: function(){
            popPage.popAllUser();
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "选择员工",
                area: ['800px', '450px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#popLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var grid = $("#popGrid");
                    var rowKey = grid.getGridParam("selrow");
                    if(!rowKey){
                        alert("请选择一条记录");
                        return ;
                    }
                    var rowData=grid.jqGrid("getRowData",rowKey);
                    vm.accidentsManagement.name=rowData.name;
                    vm.accidentsManagement.idno=rowData.idno;
                    vm.accidentsManagement.company=rowData.company;
                    vm.accidentsManagement.companyid=rowData.companyId;
                    vm.accidentsManagement.dept=rowData.department;
                    vm.accidentsManagement.post=rowData.post;

                    vm.accidentsManagement.age=rowData.age;
                    var sex=rowData.sex;
                    if(sex=='男'){
                        sex="0";
                    }else if(sex=='女'){
                        sex="1";
                    }
                    vm.accidentsManagement.sex=sex;
                    vm.accidentsManagement.phone=rowData.telphone;

                    //alert(JSON.stringify( vm.safetyEducationManagement));


                    layer.close(index);
                }
            });
        },
        getDictList: function(){
            var params = {
                dicttype:"swlb,jzfs,sglb,jddj,fplx,shcd,yesno"
            }
            $.ajax({
                type: "POST",
                url: "../dictutils/getDictList",
                contentType: "application/json",
                data: JSON.stringify(params),
                dataType:"json",
                async:false,
                cache:false,
                success: function(r){
                    if(r.code === 0){
                        vm.dictList1 = r.swlb;
                        vm.dictList2 = r.jzfs;
                        vm.dictList3 = r.sglb;
                        vm.dictList4 = r.jddj;
                        vm.dictList5 = r.fplx;
                        vm.dictList6 = r.shcd;
                        vm.dictList7 = r.yesno;


                    }else{
                        alert(r.msg);
                    }
                }
            });
        },

        dateChange:function(val){
            vm.q.eventDate1=val.split(" - ")[0];
            vm.q.eventDate2=val.split(" - ")[1];
        }

	}
});


function eventDate1(value){
    vm.q.implementationDate=value;
}


function yearChange(value){
    vm.trainingImplementationManagement.year=value;
}

function zfDate1(value){
    vm.q.estimatedTime1=value;
}
function zfDate2(value){
    vm.q.estimatedTime2=value;
}